import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  // 页面_数据名称
  state: {
    //公共的变量，这里的变量不能随便修改，只能通过触发mutations的方法才能改变
    search_historyList: uni.getStorageSync('historyList') ? JSON.parse(uni.getStorageSync('historyList')) : []
  },
  mutations: {
    //相当于同步的操作
    setSearchHistoryList(state, data) {
      state.search_historyList.unshift(data)
      state.search_historyList = [...new Set(state.search_historyList)]
      uni.setStorageSync("historyList", JSON.stringify(state.search_historyList))
    },
    clearSearchHistoryList(state) {
      state.search_historyList = []
      uni.removeStorageSync("historyList")
    }
  },
  actions: {
    //相当于异步的操作,不能直接改变state的值，只能通过触发mutations的方法才能改变
  }
})
export default store